import axios from 'axios';
import { getToken } from '@/utils/auth'

// 创建axios实例
const service = axios.create({
    baseURL: 'http://127.0.0.1:8090',
    timeout: 15000
});
// request拦截器
service.interceptors.request.use(
    config => {
        const token = getToken()
        config.headers['Content-Type'] = 'application/json;charset=UTF-8'
        if (token) {
            config.headers['Authorization'] =token
          }
        return config;
    },
    error => {
        console.log(error);
        return Promise.reject();
    }
);
// respone拦截器
service.interceptors.response.use(
    response => {
        if (response.status === 200) {
            return response.data;
        } else {
            Promise.reject();
        }
    },
    error => {
        console.log(error);
        return Promise.reject();
    }
);

export default service;
